<?php
/**
 * Truncate a block of text to a number of words. This is a very un-smart helper.
 * It doesn't take HTML or anything like that into account.
 *
 * @package     Visi
 * @subpackage  View Helpers
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2011 Coalition Technologies <joel@coalitiontechnologies.com>
 * @version     $Id$
 */
class Visi_View_Helper_TruncateWords extends Zend_View_Helper_Abstract {

    public function truncateWords($text, $num, $after = '') {
    
        $words = explode(" ", $text);
        $ret = implode(" ", array_slice($words, 0, $num));
        if (count($words) > $num) {
            $ret .= $after;
        }
        return $ret;
    
    }

}
